{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "64d5f8ff",
   "metadata": {},
   "source": [
    "# 一、用户管理功能"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4389258f",
   "metadata": {},
   "source": [
    "因为需要加入手机验证码登录的功能，我选择了自己写一个模型来实现。当然还是继承AbstractUser。\n",
    "下面来看看模型代码。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "70134c7e",
   "metadata": {
    "slideshow": {
     "slide_type": "notes"
    }
   },
   "outputs": [
    {
     "ename": "ImproperlyConfigured",
     "evalue": "Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mImproperlyConfigured\u001B[0m                      Traceback (most recent call last)",
      "\u001B[0;32m/var/folders/wk/41sn44kx3_dc1n5395nfzdrr0000gn/T/ipykernel_21407/2200180560.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontrib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mauth\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmodels\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mAbstractUser\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      2\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdb\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mmodels\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      3\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0muuid\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      4\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      5\u001B[0m \u001B[0;31m# Create your models here.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/contrib/auth/models.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m      1\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mapps\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mapps\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      2\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontrib\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mauth\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 3\u001B[0;31m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontrib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mauth\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mbase_user\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mAbstractBaseUser\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mBaseUserManager\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      4\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontrib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mauth\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mhashers\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mmake_password\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      5\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mdjango\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontrib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcontenttypes\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmodels\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mContentType\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/contrib/auth/base_user.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m     46\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     47\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 48\u001B[0;31m \u001B[0;32mclass\u001B[0m \u001B[0mAbstractBaseUser\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmodels\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mModel\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     49\u001B[0m     \u001B[0mpassword\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mmodels\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mCharField\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0m_\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'password'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mmax_length\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;36m128\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     50\u001B[0m     \u001B[0mlast_login\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mmodels\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mDateTimeField\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0m_\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'last login'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mblank\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mTrue\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnull\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;32mTrue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/db/models/base.py\u001B[0m in \u001B[0;36m__new__\u001B[0;34m(cls, name, bases, attrs, **kwargs)\u001B[0m\n\u001B[1;32m    106\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    107\u001B[0m         \u001B[0;31m# Look for an application configuration to attach the model to.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 108\u001B[0;31m         \u001B[0mapp_config\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mapps\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget_containing_app_config\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmodule\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    109\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    110\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mgetattr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmeta\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'app_label'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mis\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/apps/registry.py\u001B[0m in \u001B[0;36mget_containing_app_config\u001B[0;34m(self, object_name)\u001B[0m\n\u001B[1;32m    251\u001B[0m         \u001B[0mReturn\u001B[0m \u001B[0;32mNone\u001B[0m \u001B[0;32mif\u001B[0m \u001B[0mthe\u001B[0m \u001B[0mobject\u001B[0m \u001B[0misn\u001B[0m\u001B[0;31m'\u001B[0m\u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0many\u001B[0m \u001B[0mregistered\u001B[0m \u001B[0mapp\u001B[0m \u001B[0mconfig\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    252\u001B[0m         \"\"\"\n\u001B[0;32m--> 253\u001B[0;31m         \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcheck_apps_ready\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    254\u001B[0m         \u001B[0mcandidates\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    255\u001B[0m         \u001B[0;32mfor\u001B[0m \u001B[0mapp_config\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mapp_configs\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mvalues\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/apps/registry.py\u001B[0m in \u001B[0;36mcheck_apps_ready\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m    133\u001B[0m             \u001B[0;31m# INSTALLED_APPS raises a more helpful ImproperlyConfigured\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    134\u001B[0m             \u001B[0;31m# exception.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 135\u001B[0;31m             \u001B[0msettings\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mINSTALLED_APPS\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    136\u001B[0m             \u001B[0;32mraise\u001B[0m \u001B[0mAppRegistryNotReady\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"Apps aren't loaded yet.\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    137\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/conf/__init__.py\u001B[0m in \u001B[0;36m__getattr__\u001B[0;34m(self, name)\u001B[0m\n\u001B[1;32m     80\u001B[0m         \u001B[0;34m\"\"\"Return the value of a setting and cache it in self.__dict__.\"\"\"\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     81\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_wrapped\u001B[0m \u001B[0;32mis\u001B[0m \u001B[0mempty\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 82\u001B[0;31m             \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_setup\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mname\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m     83\u001B[0m         \u001B[0mval\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mgetattr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_wrapped\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mname\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     84\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m~/.virtualenvs/universe/lib/python3.9/site-packages/django/conf/__init__.py\u001B[0m in \u001B[0;36m_setup\u001B[0;34m(self, name)\u001B[0m\n\u001B[1;32m     61\u001B[0m         \u001B[0;32mif\u001B[0m \u001B[0;32mnot\u001B[0m \u001B[0msettings_module\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     62\u001B[0m             \u001B[0mdesc\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m(\u001B[0m\u001B[0;34m\"setting %s\"\u001B[0m \u001B[0;34m%\u001B[0m \u001B[0mname\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mif\u001B[0m \u001B[0mname\u001B[0m \u001B[0;32melse\u001B[0m \u001B[0;34m\"settings\"\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 63\u001B[0;31m             raise ImproperlyConfigured(\n\u001B[0m\u001B[1;32m     64\u001B[0m                 \u001B[0;34m\"Requested %s, but settings are not configured. \"\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m     65\u001B[0m                 \u001B[0;34m\"You must either define the environment variable %s \"\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mImproperlyConfigured\u001B[0m: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "93137280",
   "metadata": {},
   "source": [
    "region，bucket是用户注册括号，为用户创建了独立的区域，桶。"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "原始单元格格式",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}